package com.xiaoxi.adaptermode.adapter;

import com.xiaoxi.adaptermode.target.FileIOTarget;

import java.io.*;
import java.util.Properties;

/**
 * @ClassName FilePropertiestAdapter
 * @Description
 * @Author xiaoxi
 * @Date 2023/3/8 21:35
 * @Version 1.0
 */
public class FilePropertiesAdapter extends Properties implements FileIOTarget {

    @Override
    public void readFromFile(String name) throws IOException {
        load(new FileInputStream(name));
    }

    @Override
    public void writeFromFile(String name) throws IOException {
        store(new FileOutputStream(name), "write by fileProperties");
    }

    @Override
    public void setValue(String key, String value) {
        setProperty(key, value);
    }

    @Override
    public String getValue(String key) {
        return getProperty(key);
    }
}
